<?php
	include "layout.php";
	
	if (isset($_POST["submit"])) {
		extract($_POST);
		$users = mysql_query("SELECT * FROM cust WHERE Cust_FirstName = '{$fname}' AND Cust_LastName = '{$lname}' AND Cust_PW = '{$password}'");
		$count = mysql_num_rows($users);
		if ($count != 0) {
			echo <<<Error
			<script>
				alert("Error: One or more of the fields are incorrect. Please try again.");
				window.location="index.php";
			</script>
Error;
		}
		else {
			mysql_query("INSERT INTO cust (Cust_LastName, Cust_FirstName, Cust_PW) VALUES ('{$lname}', '{$fname}', '{$password}')");
			extract($user);
			$name = $fname . " " . $lname;
			echo <<<Success
			<script>
				alert("Hello {$name}! Thank you for registering for the BDPA-NY Vending Machine Application! You may now login!");
				window.location="index.php";
			</script>
Success;
		}
	}
	else {
		header("Location: index.php");
	}